package org.example.springprinciple.scope;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ScopeController {

    @Autowired
    private ApplicationContext context;
    @Autowired
    private Dog dog;

    @Autowired
    private Dog singleDog;
    @Autowired
    private Dog prototypeDog;
    @Autowired
    private Dog requestDog;
    @Autowired
    private Dog sessionDog;
    @Autowired
    private Dog applicationDog;

    @RequestMapping("/dog")
    public String dog() {
        Dog contextdog = context.getBean(Dog.class);
        Dog contextdog2 = context.getBean(Dog.class);
        Dog contextdog3 = context.getBean(Dog.class);
        Dog contextdog4 = (Dog) context.getBean("dog");
        Dog contextdog5 = (Dog) context.getBean("dog");
        Dog contextdog6 = (Dog) context.getBean("dog");
        System.out.println(contextdog);
        System.out.println(contextdog2);
        System.out.println(contextdog3);
        System.out.println(contextdog4);
        System.out.println(contextdog5);
        System.out.println(contextdog6);
        return "dog:" + dog.toString() +", contextdog:" + contextdog;
    }

    @RequestMapping("/single")
    public String single() {
        Dog contextdog = (Dog) context.getBean("singleDog");
        System.out.println(" singleDog: " + singleDog.toString() +", contextdog: " + contextdog);
        return " singleDog: " + singleDog.toString() +", contextdog: " + contextdog;
    }

    @RequestMapping("/prototype")
    public String prototype() {
        Dog contextdog = (Dog) context.getBean("prototypeDog");
        System.out.println("prototypeDog:" + prototypeDog +", contextdog:" + contextdog);
        System.out.println("prototypeDog:" + prototypeDog.toString() +", contextdog:" + contextdog);
        return "prototypeDog:" + prototypeDog.toString() +", contextdog:" + contextdog;
    }

    @RequestMapping("/request")
    public String request() {
        Dog contextdog = (Dog) context.getBean("requestDog");
        System.out.println("requestDog:" + requestDog.toString() +", contextdog:" + contextdog);
        return "requestDog:" + requestDog.toString() +", contextdog:" + contextdog;
    }

    @RequestMapping("/session")
    public String session() {
        Dog contextdog = (Dog) context.getBean("sessionDog");
        System.out.println("sessionDog:" + sessionDog.toString() +", contextdog:" + contextdog);
        return "sessionDog:" + sessionDog.toString() +", contextdog:" + contextdog;
    }

    @RequestMapping("/application")
    public String application() {
        Dog contextdog = (Dog) context.getBean("applicationDog");
        System.out.println("applicationDog:" + applicationDog.toString() +", contextdog:" + contextdog);
        return "applicationDog:" + applicationDog.toString() +", contextdog:" + contextdog;
    }
}
